import 'package:bot_toast/bot_toast.dart';
import 'package:flame/flame.dart';
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_umplus/flutter_umplus.dart';
import 'package:flutterzhuyili/page/gameSelect.dart';
import 'package:flutterzhuyili/page/router.dart';
import 'package:flutterzhuyili/page/splash.dart';
import 'package:flutterzhuyili/utils/globalData.dart';
import 'package:flutterzhuyili/utils/shared_preferences.dart';
import 'package:flutterzhuyili/utils/sqlCreate.dart';
import 'package:provider/provider.dart';

import 'model/theme.dart';

SpUtil sp;

bool hasShowAD = false;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  sp = await SpUtil.getInstance();
  final providerDb = new Provider_db();
  Flame.util.fullScreen();
  await providerDb.init(true);

  final theme = CustomTheme(false);
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider.value(value: theme),
    ],
    child: MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      builder: BotToastInit(),
      initialRoute: '/',
      onGenerateRoute: onGenerateRoute,
      title: '注意力训练',
      supportedLocales: [const Locale('zh', 'CH')],
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
      ],
      theme: Provider.of<CustomTheme>(context).isDark
          ? ThemeData.dark()
          : ThemeData(
              primarySwatch: Colors.blue,
              visualDensity: VisualDensity.adaptivePlatformDensity,
            ),
      darkTheme: ThemeData(
        brightness: Brightness.dark,
      ),
      home: SplashPage(),

//      MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }

  void initUmeng() {
    FlutterUmplus.init(
      GlobalUtils.instance.uMengId,
      channel: '自定义',
      reportCrash: false,
      logEnable: true,
      encrypt: true,
    );
  }
}
